﻿using System;
using GameEditor;
using GameEditor.View.Components;
using GameEngine.Clients.Silverlight.View.Components;
using GameEngine.Model.Data.implementation;
using GameEngine.View.Components;
using System.Windows;
using SilverlightClientEditor.View.Components;
using SilverlightClientEditor.View;
using GameEditor.View;
using GameEngine;
using GameEngine.Model;
using GameEngine.Clients.Silverlight.View;
using GameEngine.View;
using GameEngine.Clients.Silverlight;
using GameEngine.Model.Data;
using System.Windows.Controls;

namespace SilverlightClientEditor
{
    //public class SampleSilverlightEditorViewFacade : SilverlightEditorViewFacade<EditorGameUC, EditorLevelUC>
    //{
    //    //override public GameEditorMediator<GamePropertiesEditorUC, LevelPropertiesEditorUC, WorldPropertiesEditorUC, MapPropertiesEditorUC, ResourcePropertiesEditorUC, ViewEditorUC, ShapePropertiesEditorUC, ThingTypePropertiesEditorUC, ThingPropertiesEditorUC, EditorGameUC, EditorLevelUC, WorldUC, MapUC, ItemUC, FrameworkElement, int>
    //    //    CreateGameEditorMediator(
    //    //    string name, GameEditorUC view, IGameDataProxy<int> game,
    //    //    WorldMediator<WorldUC, MapUC, ItemUC, int, FrameworkElement> worldMediator,
    //    //    //GameMediator<MyGameView, MyLevelView, MyWorldView, MyMapView, MyItemView, MyIdType, MyBaseUIElementType> gameMediator,
    //    //    GamePropertiesEditor_MenuMediator<GamePropertiesEditorUC, int> gameEditorMenuMediator,
    //    //    LevelPropertiesEditor_MenuMediator<LevelPropertiesEditorUC, int> levelEditorMenuMediator,
    //    //    WorldPropertiesEditor_MenuMediator<WorldPropertiesEditorUC, int> worldEditorMenuMediator,
    //    //    MapPropertiesEditor_Mediator<MapPropertiesEditorUC, MapUC, ItemUC, int, FrameworkElement> mapEditorMenuMediator,
    //    //    //ResourcePropertiesEditor_MenuMediator<ResourcePropertiesEditorUC, int> resourceEditorMenuMediator,
    //    //    //ViewPropertiesEditor_MenuMediator<ViewEditorUC, int> viewEditorMenuMediator,
    //    //    //ThingTypePropertiesEditor_MenuMediator<ThingTypePropertiesEditorUC, int> thingTypeEditorMenuMediator,
    //    //    ThingPropertiesEditor_MenuMediator<ThingPropertiesEditorUC, int> thingEditorMenuMediator,
    //    //    string outCommand)
    //    //{
    //    //    return new SilverlightGameEditorMediator(name, view, game, worldMediator, gameEditorMenuMediator, levelEditorMenuMediator, worldEditorMenuMediator,
    //    //        mapEditorMenuMediator, thingEditorMenuMediator, outCommand);
    //    //}

    //}

    public class SilverlightEditorFacade : GameEditorFacade
    {
        public new static SilverlightEditorFacade Instance
        {
            get
            {
                if (GameEditorFacade.Instance == null)
                    GameEditorFacade.instance = new SilverlightEditorFacade();
                return GameEditorFacade.Instance as SilverlightEditorFacade;
            }
        }
        protected SilverlightEditorFacade() : base() { }

        override protected void CreateModelFacade()
        {
            new SilverlightEditorModelFacade();
        }

        protected override void CreateViewFacade()
        {
            new SilverlightEditorViewFacade();
        }

        //public GameEditorUC Start(GameVO<int> game, string outCommand)
        //{
        //    return SilverlightEditorViewFacade.Helper.Start(game, outCommand);
        //}
    }

    public class SilverlightEditorViewFacade : GameEditorViewFacade<int>
    {
        override protected void InitializeController()
        {
            base.InitializeController();

            //ApplicationFacade.Instance.RegisterCommand(
            //    SilverlightEditorFacade.EDITORSTARTUP_COMMAND,
            //    typeof(EditorStartup_Command));

            //ApplicationFacade.Instance.RegisterCommand(
            //    SilverlightEditorFacade.EDITORFINISH_COMMAND,
            //    typeof(EditorFinish_Command));
        }

        #region Views
        //override public GameEditorUC CreateGameEditorView() { return new GameEditorUC(); }

        override public IGameEditorMenuView<int> CreateGameEditorMenuView() { return new GamePropertiesEditorUC(); }

        override public ILevelEditorMenuView<int> CreateLevelEditorMenuView() { return new LevelPropertiesEditorUC(); }

        override public IWorldEditorMenuView<int> CreateWorldEditorMenuView() { return new WorldPropertiesEditorUC(); }

        override public IMapEditorMenuView CreateMapEditorMenuView() { return new MapPropertiesEditorUC(); }

        override public IViewEditorMenuView<int> CreateViewEditorMenuView() { return new ViewEditorUC(); }

        override public IShapeEditorMenuView<int> CreateShapeEditorMenuView() { return new ShapePropertiesEditorUC(); }

        override public IThingEditorMenuView<int> CreateThingEditorMenuView() { return new ThingPropertiesEditorUC(); }

        override public IThingTypeEditorMenuView<int> CreateThingTypeEditorMenuView() { return new ThingTypePropertiesEditorUC(); }

        override public IResourceEditorMenuView<int> CreateResourceEditorMenuView() { return new ResourcePropertiesEditorUC(); }
        #endregion

        #region Mediators
        override public GamePropertiesEditor_MenuMediator<int> CreateGameEditorMenuMediator(string name, IGameEditorMenuView<int> view, IGameDataProxy<int> dataProxy)
        {
            return new SilverlightGameEditorMenuMediator(name, view,dataProxy, SilverlightEditorFacade.GAMEPROPERTIESEDITOR_MENUACTION_COMMAND);
        }

        override public LevelPropertiesEditor_MenuMediator<int> CreateLevelEditorMenuMediator(string name, ILevelEditorMenuView<int> view)
        {
            return new SilverlightLevelEditorMenuMediator(name, view, SilverlightEditorFacade.LEVELPROPERTIESEDITOR_MENUACTION_COMMAND);
        }

        override public WorldPropertiesEditor_MenuMediator<int> CreateWorldEditorMenuMediator(string name, IWorldEditorMenuView<int> view, IWorldDataProxy<int> dataProxy)
        {
            return new SilverlightWorldEditorMenuMediator(name, view, SilverlightEditorFacade.WORLDPROPERTIESEDITOR_MENUACTION_COMMAND, dataProxy);
        }

        override public MapPropertiesEditor_Mediator<int> CreateMapEditorMenuMediator(
            string name,
            IMapEditorMenuView view, 
            IMapDataProxy<int> dataProxy)
        {
            return new SilverlightMapEditorMenuMediator(name, view, dataProxy);
        }

        override public ViewPropertiesEditor_MenuMediator<int> CreateViewEditorMenuMediator(string name, IViewEditorMenuView<int> view, IViewDataProxy<int> dataProxy)
        {
            return new SilverlightViewEditorMenuMediator(name, view, dataProxy, SilverlightEditorFacade.VIEWPROPERTIESEDITOR_MENUACTION_COMMAND);
        }

        override public ShapePropertiesEditor_MenuMediator<int> CreateShapeEditorMenuMediator(string name, IShapeEditorMenuView<int> view, IViewDataProxy<int> dataProxy, IShapeVOId shape)
        {
            return new SilverlightShapeEditorMenuMediator(name, view, dataProxy, shape,SilverlightEditorFacade.SHAPEPROPERTIESEDITOR_MENUACTION_COMMAND);
        }

        override public ThingPropertiesEditor_MenuMediator<int> CreateThingEditorMenuMediator(string name, IThingEditorMenuView<int> view, IThingDataProxy<int> dataProxy)
        {
            return new SilverlightThingEditorMenuMediator(name, view, dataProxy, SilverlightEditorFacade.THINGPROPERTIESEDITOR_MENUACTION_COMMAND);
        }

        override public ThingTypePropertiesEditor_MenuMediator<int> CreateThingTypeEditorMenuMediator(string name, IThingTypeEditorMenuView<int> view)
        {
            return new SilverlightThingTypeEditorMenuMediator(name, view);
        }

        override public ResourcePropertiesEditor_MenuMediator<int> CreateResourceEditorMenuMediator(string name, IResourceEditorMenuView<int> view,IResourceDataProxy dataProxy)
        {
            return new SilverlightResourceEditorMenuMediator(name, view, dataProxy, SilverlightEditorFacade.RESOURCEEDITORMENU_ACTION_COMMAND);
        }
        #endregion
    }

    public class SilverlightEditorModelFacade : GameEditorModelFacade<int>
    {      
    }
}
